//
// Created by wangwanlong on 2024/11/4.
//
#ifndef MKAHYPAR_METRICS_H
#define MKAHYPAR_METRICS_H
#include "mkahypar/utils/typedef.h"
//定义目标函数
namespace mkahypar{
  struct Metrics{
    using GainType = int64_t;
    GainType block_penalty;//block超出惩罚
    GainType edge_penalty;//fpga互联量超出惩罚
    GainType hop_penalty;//赛题定义的目标函数
    GainType obj;

    Metrics():block_penalty(0),edge_penalty(0),hop_penalty(0),obj(0){

    }
    //更新目标函数
    void updateMetric(GainType& b,GainType&e,GainType& h){
      block_penalty = b;
      edge_penalty = e;
      hop_penalty = h;
    }
    GainType getMetric(){
      return obj;
    }
    void updateObj(){
      obj = block_penalty + edge_penalty + hop_penalty;
    }

    Metrics &operator+=(const Metrics &obj) {
      if (this != &obj) {
        (*this).block_penalty += obj.block_penalty;
        (*this).edge_penalty += obj.edge_penalty;
        (*this).hop_penalty += obj.hop_penalty;
        (*this).obj += obj.obj;

      }
      return *this;
    }

    Metrics &operator-=(const Metrics &obj) {
      if (this != &obj) {
        (*this).block_penalty -= obj.block_penalty;
        (*this).edge_penalty -= obj.edge_penalty;
        (*this).hop_penalty -= obj.hop_penalty;
        (*this).obj -= obj.obj;
      }
      return *this;
    }

    Metrics operator+(const Metrics &rhs) const {
      Metrics result = *this;
      result += rhs;
      return result;
    }

    Metrics operator-(const Metrics &rhs) const {
      Metrics result = *this;
      result -= rhs;
      return result;
    }

    void print(){
      LOG<<"block violate:"<<block_penalty;
      LOG<<"edge violate:"<<edge_penalty;
      LOG<<"hop violate:"<<hop_penalty;
      LOG<<"obj = "<<obj;
    }


  };
}
#endif //MKAHYPAR_METRICS_H
